package com.it.deliveryaddress.controller;


import com.it.common.entity.DeliveryAddress;
import com.it.deliveryaddress.service.DeliveryAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@RequestMapping("/deliveryAddress")
public class DeliveryAddressController {

    @Autowired
    private DeliveryAddressService deliveryAddressService;

    @GetMapping("/listDeliveryAddressByUserId")
    public ResponseEntity<Object> listDeliveryAddressByUserId(@RequestParam String userId){
        List<DeliveryAddress> list = deliveryAddressService.listDeleveryAddressByUserId(userId);
        return new ResponseEntity<>(list, HttpStatus.OK);

    }

    @PostMapping("/saveDeliveryAddress")
    public Integer saveDeliveryAddress(@RequestBody DeliveryAddress  deliveryAddress){
//        System.out.println(deliveryAddress);
        return deliveryAddressService.saveDeliveryAddress(deliveryAddress);
    }

    @PostMapping("/removeDeliveryAddress")
    public int removeDeliveryAddress(@RequestBody DeliveryAddress  deliveryAddress) {
//        System.out.println(deliveryAddress);
        return deliveryAddressService.removeDeliveryAddress(deliveryAddress.getDaId());
//        return 0;
    }

    @PostMapping ("/getDeliveryAddressById")
    public DeliveryAddress getDeliveryAddressById(@RequestBody DeliveryAddress deliveryAddress) {
        System.out.println(deliveryAddress);
        DeliveryAddress address=deliveryAddressService.getDeliveryAddressById(deliveryAddress.getDaId());
//        System.out.println(address);
//        return deliveryAddressService.getDeliveryAddressById(deliveryAddress.getDaId());
        return address;
    }

    @PostMapping("/updateDeliveryAddress")
    public int updateDeliveryAddress(@RequestBody DeliveryAddress deliveryAddress){
        System.out.println(deliveryAddress);
        return deliveryAddressService.updateDeliveryAddress(deliveryAddress);
//        return 0;
    }
}
